package com.hnfnu.mapper;

import com.hnfnu.protocol.dto.DisburseDTO;
import com.hnfnu.entity.Disburse;
import com.hnfnu.protocol.param.DisburseProgressParam;
import com.hnfnu.protocol.vo.ProjectDisburseProgressVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DisburseMapper {
    @Insert("insert into disburse (project_id, amount, address, time, description, progress) values (#{projectId}, #{amount}, #{address}, #{time},#{description},#{progress})")
    Boolean insert(Disburse disburse);

    @Select("SELECT project.name AS projectName, purpose_detail.name AS purposeDetailName, disburse.amount, disburse.address, disburse.time,disburse.description, disburse.progress\n" +
            "FROM disburse\n" +
            "JOIN project ON disburse.project_id = project.id\n" +
            "JOIN purpose_detail ON project.purpose_detail_id = purpose_detail.id;")
    List<DisburseDTO> list();

    @Select("select address, time, description,progress from disburse where project_id = #{projectId};")
    List<ProjectDisburseProgressVO> listProgress(Integer projectId);

    @Select("select distinct amount from disburse where project_id = #{projectId};")
    Double getAmountByProjectId(Integer projectId);

    @Select("SELECT project.name AS projectName, purpose_detail.name AS purposeDetailName, disburse.amount, disburse.address, disburse.time,disburse.description, disburse.progress\n" +
            "FROM disburse\n" +
            "JOIN project ON disburse.project_id = project.id\n" +
            "JOIN purpose_detail ON project.purpose_detail_id = purpose_detail.id\n" +
            "WHERE project.id = #{projectId};")
    List<DisburseDTO> listByProjectId(Integer projectId);

    @Select("select sum(amount) from disburse")
    Double getTotalDisburse();
}
